<?php
/**
 * 装修公司
 */
namespace App\Http\ControllersAdmin;

use App\Service\LiveRecordService;
use App\Validation\LiveRecordValidation;
use App\Validation\LiveRecordSearchValidation;
use App\Validation\DeleteValidation;

class LiveRecordController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new LiveRecordSearchValidation, $this->request->getJsonRawBody());

		$data = LiveRecordService::getList($raw);
		$count = LiveRecordService::getList($raw, TRUE);

		$assign = [
			'total' => $count,
			'list'  => $data
		];
		return $this->echoJson($assign);
	}

	/**
	 * [createAction 创建]
	 * @return [type] [description]
	 */
	public function createAction()
	{
		$this->getUser();
		$raw = $this->validation(new LiveRecordValidation, $this->request->getJsonRawBody());
		$data = LiveRecordService::save($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = LiveRecordService::getInfo($id);
		return $this->echoJson($data);
	}

	/**
	 * [updateAction 更新]
	 * @return [type] [description]
	 */
	public function updateAction()
	{
		$this->getUser();
		$raw = $this->validation(new LiveRecordValidation, $this->request->getJsonRawBody());
		$data = LiveRecordService::save($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = LiveRecordService::delete($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [restoreAction 恢复]
	 * @return [type] [description]
	 */
	public function restoreAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = LiveRecordService::restore($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 彻底删除]
	 * @return [type] [description]
	 */
	public function foreverAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = LiveRecordService::forever($raw->id);
		return $this->echoJson('ok');
	}
}